package com.jcfy.project.module.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jcfy.framework.aspectj.lang.annotation.Log;
import com.jcfy.framework.aspectj.lang.enums.BusinessType;
import com.jcfy.project.module.domain.TAccount;
import com.jcfy.project.module.service.ITAccountService;
import com.jcfy.framework.web.controller.BaseController;
import com.jcfy.framework.web.domain.AjaxResult;
import com.jcfy.common.utils.poi.ExcelUtil;
import com.jcfy.framework.web.page.TableDataInfo;

/**
 * 账户Controller
 *
 * @author jiangfeng
 * @date 2020-08-05
 */
@RestController
@RequestMapping("/module/account" )
public class TAccountController extends BaseController {
    @Autowired
    private ITAccountService tAccountService;

    /**
     * 查询账户列表
     */
    @PreAuthorize("@ss.hasPermi('module:account:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(TAccount tAccount) {
        startPage();
        List<TAccount> list = tAccountService.selectTAccountList(tAccount);
        return getDataTable(list);
    }

    /**
     * 导出账户列表
     */
    @PreAuthorize("@ss.hasPermi('module:account:export')" )
    @Log(title = "账户" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TAccount tAccount) {
        List<TAccount> list = tAccountService.selectTAccountList(tAccount);
        ExcelUtil<TAccount> util = new ExcelUtil<TAccount>(TAccount. class);
        return util.exportExcel(list, "account" );
    }

    /**
     * 获取账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:account:query')" )
    @GetMapping(value = "/{accountId}" )
    public AjaxResult getInfo(@PathVariable("accountId" ) Long accountId) {
        return AjaxResult.success(tAccountService.selectTAccountById(accountId));
    }

    /**
     * 新增账户
     */
    @PreAuthorize("@ss.hasPermi('module:account:add')" )
    @Log(title = "账户" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAccount tAccount) {
        return toAjax(tAccountService.insertTAccount(tAccount));
    }

    /**
     * 修改账户
     */
    @PreAuthorize("@ss.hasPermi('module:account:edit')" )
    @Log(title = "账户" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAccount tAccount) {
        return toAjax(tAccountService.updateTAccount(tAccount));
    }

    /**
     * 删除账户
     */
    @PreAuthorize("@ss.hasPermi('module:account:remove')" )
    @Log(title = "账户" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{accountIds}" )
    public AjaxResult remove(@PathVariable Long[] accountIds) {
        return toAjax(tAccountService.deleteTAccountByIds(accountIds));
    }
}
